/**
 *@Title: SpecialClaimServiceImpl.java
 * @author: 胡彪
 * @date: 2013-5-30 下午05:33:58
 * @Description:
 * @version: V1.0
 */
package com.imonsoft.sqm.service.business.supplier_quality;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindingResult;
import com.google.gson.reflect.TypeToken;
import com.imonsoft.common.constant.ConstantSqm;
import com.imonsoft.common.exception.SystemException;
import com.imonsoft.common.httpModel.DataGrid;
import com.imonsoft.common.httpModel.Pager;
import com.imonsoft.common.httpModel.ReturnMessage;
import com.imonsoft.common.util.JsonUtil;
import com.imonsoft.common.util.StringUtil;
import com.imonsoft.sqm.dao.business.supplier_quality.Special_ClaimDAO;
import com.imonsoft.sqm.pojo.basedata.Supplier;
import com.imonsoft.sqm.pojo.business.supplier_quality.Special_Claim;
import com.imonsoft.sqm.pojo.business.supplier_quality.Special_ClaimExample;
import com.imonsoft.sqm.service.basedata.SupplierService;
import com.imonsoft.sqm.validator.business.supplier_quality.SpecialClaimValidator;
import com.imonsoft.sqm.vo.business.supplier_quality.SpecialClaimVo;
import com.imonsoft.sqm.web.excel.SpecialClaim.SpecialClaimImportDto;

/*
 * *
 */
@Service("specialClaimService")
public class SpecialClaimServiceImpl implements SpecialClaimService {

	@Autowired
	private Special_ClaimDAO special_ClaimDAO;

	@Autowired
	private SupplierService supplierService;

	@Autowired
	private SpecialClaimValidator specialClaimValidator;

	@Override
	public int delete(Long id) {
		return 0;
	}

	@Override
	public List<Special_Claim> findList(Special_Claim entity) {
		Special_ClaimExample example = new Special_ClaimExample();
		Special_ClaimExample.Criteria criteria = example.createCriteria();
		criteria.andStateNotEqualTo(ConstantSqm.STATUS_DELETE);
		criteria.andSupplierIdEqualTo(entity.getSupplierId());
		criteria.andYearEqualTo(entity.getYear());
		return special_ClaimDAO.selectSpecial_ClaimByExample(example);
	}

	@Override
	public Special_Claim get(Long id) {
		// TODO Auto-generated method stub
		return special_ClaimDAO.selectSpecial_ClaimByPrimaryKey(id);
	}

	@Override
	public DataGrid<Special_Claim> getDataGrid(Special_Claim entity, Pager pager) {
		return null;
	}

	@Override
	public Long insert(Special_Claim entity) {
		return null;
	}

	@Override
	public int update(Special_Claim entity) {
		return 0;
	}

	@Override
	public DataGrid<SpecialClaimVo> getDataGridVoBy(Special_Claim entity, Pager pager) {

		return special_ClaimDAO.getDataGridVoBy(entity, pager);
	}

	@Override
	public SpecialClaimVo getModifyData(Long id, String year) {

		SpecialClaimVo vo = new SpecialClaimVo();

		Supplier supplier = supplierService.get(id);
		vo.setId(supplier.getId().toString());
		vo.setCode(supplier.getCode());
		vo.setName(supplier.getName());
		vo.setType(supplier.getMaterialGroup());

		for (int i = 1; i <= 12; i++) {
			Special_Claim bean = null;
			Special_ClaimExample example = new Special_ClaimExample();
			Special_ClaimExample.Criteria criteria = example.createCriteria();
			criteria.andStateNotEqualTo(ConstantSqm.STATUS_DELETE);
			criteria.andSupplierIdEqualTo(Integer.parseInt(id.toString()));
			criteria.andYearEqualTo(year);
			criteria.andMonthEqualTo(StringUtil.paddingZero(String.valueOf(i),2));
			List<Special_Claim> list = special_ClaimDAO.selectSpecial_ClaimByExample(example);
			if (list.size() != 0) {
				bean = list.get(0);
				if (i == 1) {
					vo.setSpe1i1(StringUtil.fixup(bean.getIncident1()));
					vo.setSpe1i2(StringUtil.fixup(bean.getIncident2()));
					vo.setSpe1i3(StringUtil.fixup(bean.getIncident3()));
					vo.setSpe1i4(StringUtil.fixup(bean.getIncident4()));
					vo.setValue1(StringUtil.fixup(bean.getValue()));
					vo.setComment1(bean.getComment());
				} else if (i == 2) {
					vo.setSpe2i1(StringUtil.fixup(bean.getIncident1()));
					vo.setSpe2i2(StringUtil.fixup(bean.getIncident2()));
					vo.setSpe2i3(StringUtil.fixup(bean.getIncident3()));
					vo.setSpe2i4(StringUtil.fixup(bean.getIncident4()));
					vo.setValue2(StringUtil.fixup(bean.getValue()));
					vo.setComment2(bean.getComment());
				} else if (i == 3) {
					vo.setSpe3i1(StringUtil.fixup(bean.getIncident1()));
					vo.setSpe3i2(StringUtil.fixup(bean.getIncident2()));
					vo.setSpe3i3(StringUtil.fixup(bean.getIncident3()));
					vo.setSpe3i4(StringUtil.fixup(bean.getIncident4()));
					vo.setValue3(StringUtil.fixup(bean.getValue()));
					vo.setComment3(bean.getComment());
				} else if (i == 4) {
					vo.setSpe4i1(StringUtil.fixup(bean.getIncident1()));
					vo.setSpe4i2(StringUtil.fixup(bean.getIncident2()));
					vo.setSpe4i3(StringUtil.fixup(bean.getIncident3()));
					vo.setSpe4i4(StringUtil.fixup(bean.getIncident4()));
					vo.setValue4(StringUtil.fixup(bean.getValue()));
					vo.setComment4(bean.getComment());
				} else if (i == 5) {
					vo.setSpe5i1(StringUtil.fixup(bean.getIncident1()));
					vo.setSpe5i2(StringUtil.fixup(bean.getIncident2()));
					vo.setSpe5i3(StringUtil.fixup(bean.getIncident3()));
					vo.setSpe5i4(StringUtil.fixup(bean.getIncident4()));
					vo.setValue5(StringUtil.fixup(bean.getValue()));
					vo.setComment5(bean.getComment());
				} else if (i == 6) {
					vo.setSpe6i1(StringUtil.fixup(bean.getIncident1()));
					vo.setSpe6i2(StringUtil.fixup(bean.getIncident2()));
					vo.setSpe6i3(StringUtil.fixup(bean.getIncident3()));
					vo.setSpe6i4(StringUtil.fixup(bean.getIncident4()));
					vo.setValue6(StringUtil.fixup(bean.getValue()));
					vo.setComment6(bean.getComment());
				} else if (i == 7) {
					vo.setSpe7i1(StringUtil.fixup(bean.getIncident1()));
					vo.setSpe7i2(StringUtil.fixup(bean.getIncident2()));
					vo.setSpe7i3(StringUtil.fixup(bean.getIncident3()));
					vo.setSpe7i4(StringUtil.fixup(bean.getIncident4()));
					vo.setValue7(StringUtil.fixup(bean.getValue()));
					vo.setComment7(bean.getComment());
				} else if (i == 8) {
					vo.setSpe8i1(StringUtil.fixup(bean.getIncident1()));
					vo.setSpe8i2(StringUtil.fixup(bean.getIncident2()));
					vo.setSpe8i3(StringUtil.fixup(bean.getIncident3()));
					vo.setSpe8i4(StringUtil.fixup(bean.getIncident4()));
					vo.setValue8(StringUtil.fixup(bean.getValue()));
					vo.setComment8(bean.getComment());
				} else if (i == 9) {
					vo.setSpe9i1(StringUtil.fixup(bean.getIncident1()));
					vo.setSpe9i2(StringUtil.fixup(bean.getIncident2()));
					vo.setSpe9i3(StringUtil.fixup(bean.getIncident3()));
					vo.setSpe9i4(StringUtil.fixup(bean.getIncident4()));
					vo.setValue9(StringUtil.fixup(bean.getValue()));
					vo.setComment9(bean.getComment());
				} else if (i == 10) {
					vo.setSpe10i1(StringUtil.fixup(bean.getIncident1()));
					vo.setSpe10i2(StringUtil.fixup(bean.getIncident2()));
					vo.setSpe10i3(StringUtil.fixup(bean.getIncident3()));
					vo.setSpe10i4(StringUtil.fixup(bean.getIncident4()));
					vo.setValue10(StringUtil.fixup(bean.getValue()));
					vo.setComment10(bean.getComment());
				} else if (i == 11) {
					vo.setSpe11i1(StringUtil.fixup(bean.getIncident1()));
					vo.setSpe11i2(StringUtil.fixup(bean.getIncident2()));
					vo.setSpe11i3(StringUtil.fixup(bean.getIncident3()));
					vo.setSpe11i4(StringUtil.fixup(bean.getIncident4()));
					vo.setValue11(StringUtil.fixup(bean.getValue()));
					vo.setComment11(bean.getComment());
				} else if (i == 12) {
					vo.setSpe12i1(StringUtil.fixup(bean.getIncident1()));
					vo.setSpe12i2(StringUtil.fixup(bean.getIncident2()));
					vo.setSpe12i3(StringUtil.fixup(bean.getIncident3()));
					vo.setSpe12i4(StringUtil.fixup(bean.getIncident4()));
					vo.setValue12(StringUtil.fixup(bean.getValue()));
					vo.setComment12(bean.getComment());
				}
			}
		}

		return vo;
	}

	@Override
	public void txUpdateOrAddSpecialClaim(String specialClaimDetail, String specialClaim) throws IllegalAccessException, InvocationTargetException {
		Special_Claim special_Claim = null;
		Map<String, String> map = null;
		List<Map<String, String>> list = null;
		List<Special_Claim> claimList = new ArrayList<Special_Claim>();

		special_Claim = richSpecialClaimBean(specialClaimDetail, specialClaim, special_Claim, map, list, claimList);

		Supplier supplier = supplierService.get(special_Claim.getId());

		for (int i = 1; i <= 12; i++) {
			Special_Claim bean = null;
			Special_ClaimExample example = new Special_ClaimExample();
			Special_ClaimExample.Criteria criteria = example.createCriteria();
			criteria.andStateNotEqualTo(ConstantSqm.STATUS_DELETE);
			criteria.andSupplierIdEqualTo(Integer.parseInt(special_Claim.getId().toString()));
			criteria.andYearEqualTo(special_Claim.getYear());
			criteria.andMonthEqualTo(StringUtil.paddingZero(String.valueOf(i),2));
			List<Special_Claim> specialClaimList = special_ClaimDAO.selectSpecial_ClaimByExample(example);
			// 修改
			if (specialClaimList.size() != 0) {
				bean = specialClaimList.get(0);
				for (Special_Claim special_Claim2 : claimList) {
					if (i == Integer.parseInt(special_Claim2.getMonth())) {
						bean.setComment(special_Claim2.getComment());
						bean.setValue(special_Claim2.getValue());
						bean.setIncident1(special_Claim2.getIncident1());
						bean.setIncident2(special_Claim2.getIncident2());
						bean.setIncident3(special_Claim2.getIncident3());
						bean.setIncident4(special_Claim2.getIncident4());
						break;
					}
				}
				special_ClaimDAO.updateSpecial_ClaimByPrimaryKey(bean);

			} else {

				for (Special_Claim special_Claim2 : claimList) {
					if (i == Integer.parseInt(special_Claim2.getMonth())) {
						// 新增
						Special_Claim claim = new Special_Claim();
						claim.setComment(special_Claim2.getComment());
						claim.setValue(special_Claim2.getValue());
						claim.setIncident1(special_Claim2.getIncident1());
						claim.setIncident2(special_Claim2.getIncident2());
						claim.setIncident3(special_Claim2.getIncident3());
						claim.setIncident4(special_Claim2.getIncident4());
						claim.setYear(special_Claim.getYear());
						claim.setSupplierId(Integer.parseInt(supplier.getId().toString()));
						claim.setSupplierCode(supplier.getCode());
						claim.setSupplierName(supplier.getName());
						claim.setMonth(special_Claim2.getMonth());
						claim.setState(ConstantSqm.STATUS_NORMAL);

						if (!StringUtil.isBlank(claim.getComment()) || claim.getValue() != null || claim.getIncident1() != null || claim.getIncident2() != null || claim.getIncident3() != null || claim.getIncident4() != null) {
							special_ClaimDAO.insertSpecial_Claim(claim);
						}
						break;
					}
				}

			}
		}
	}

	@Override
	public void txAddSpecialClaim(String specialClaimDetail, String specialClaim, ReturnMessage message, BindingResult result) throws IllegalAccessException, InvocationTargetException {

		Special_Claim special_Claim = null;
		Map<String, String> map = null;
		List<Map<String, String>> list = null;
		List<Special_Claim> claimList = new ArrayList<Special_Claim>();

		special_Claim = richSpecialClaimBean(specialClaimDetail, specialClaim, special_Claim, map, list, claimList);
		Supplier supplier = supplierService.get(Long.valueOf(special_Claim.getSupplierId()));
		special_Claim.setSupplierId(supplier.getId().intValue());
		special_Claim.setSupplierCode(supplier.getCode());
		specialClaimValidator.methodAddValidate(special_Claim, result);
		if (result.hasErrors()) {
			message.setObj(specialClaimValidator.getErrors(result));
		} else {

			List<Special_Claim> claimList1=findListByStateDelete(special_Claim);
			if (claimList1 != null && claimList1.size() > 0) {
				for (Special_Claim special_Claim2 : claimList1) {
					special_Claim2.setComment(null);
					special_Claim2.setIncident1(null);
					special_Claim2.setIncident2(null);
					special_Claim2.setIncident3(null);
					special_Claim2.setIncident4(null);
					special_Claim2.setValue(null);
					special_Claim2.setState(ConstantSqm.STATUS_NORMAL);
					special_ClaimDAO.updateSpecial_ClaimByPrimaryKey(special_Claim2);
				} 
				 
			} 
			
			
			
			
			for (int i = 1; i <= 12; i++) {
				for (Special_Claim special_Claim2 : claimList) {
					if (i == Integer.parseInt(special_Claim2.getMonth())) {
						// 新增
						Special_Claim claim = new Special_Claim();
						claim.setComment(special_Claim2.getComment());
						claim.setValue(special_Claim2.getValue());
						claim.setIncident1(special_Claim2.getIncident1());
						claim.setIncident2(special_Claim2.getIncident2());
						claim.setIncident3(special_Claim2.getIncident3());
						claim.setIncident4(special_Claim2.getIncident4());
						claim.setYear(special_Claim.getYear());
						claim.setSupplierId(Integer.parseInt(supplier.getId().toString()));
						claim.setSupplierCode(supplier.getCode());
						claim.setSupplierName(supplier.getName());
						claim.setMonth(special_Claim2.getMonth());
						claim.setState(ConstantSqm.STATUS_NORMAL);

						if (!StringUtil.isBlank(claim.getComment()) || claim.getValue() != null || claim.getIncident1() != null || claim.getIncident2() != null || claim.getIncident3() != null || claim.getIncident4() != null) {
							List<Special_Claim> bean=findListByStateMonth(claim);
							if (bean != null && bean.size() > 0) {
								Special_Claim obj = bean.get(0);
								obj.setComment(claim.getComment());
								obj.setIncident1(claim.getIncident1());
								obj.setIncident2(claim.getIncident2());
								obj.setIncident3(claim.getIncident3());
								obj.setIncident4(claim.getIncident4());
								obj.setValue(claim.getValue());
								special_ClaimDAO.updateSpecial_ClaimByPrimaryKey(obj);
							} else{
								special_ClaimDAO.insertSpecial_Claim(claim);	
							}
						}
						break;
					}
				}
			}
			message.setSuccess(true);
			message.setMsg(ConstantSqm.OPERATE_SUCCESS);
		}
	}

	private Special_Claim richSpecialClaimBean(String specialClaimDetail, String specialClaim, Special_Claim special_Claim, Map<String, String> map, List<Map<String, String>> list, List<Special_Claim> claimList)
			throws IllegalAccessException, InvocationTargetException {
		if (StringUtil.isNotBlank(specialClaim)) {
			map = JsonUtil.json2Bean(specialClaim, new TypeToken<Map<String, String>>() {
			});
		}
		if (StringUtil.isNotBlank(specialClaimDetail)) {
			// 把json字符串转换成对象
			list = JsonUtil.json2Bean(specialClaimDetail, new TypeToken<List<Map<String, String>>>() {
			});
		}

		if (map != null) {
			special_Claim = new Special_Claim();
			BeanUtils.populate(special_Claim, map);
		}

		if (list != null) {
			for (int i = 0; i < list.size(); i++) {
				Map<String, String> detailMap = list.get(i);
				Special_Claim bean = new Special_Claim();
				BeanUtils.populate(bean, detailMap);
				claimList.add(bean);
			}
		}
		return special_Claim;
	}

	@Override
	public void deleteSpecialClaim(String detail) throws Exception {

		List<Special_Claim> claimList = new ArrayList<Special_Claim>();
		List<Map<String, String>> list = null;
		if (StringUtil.isNotBlank(detail)) {
			// 把json字符串转换成对象
			list = JsonUtil.json2Bean(detail, new TypeToken<List<Map<String, String>>>() {
			});
		}
		if (list != null) {
			for (int i = 0; i < list.size(); i++) {
				Map<String, String> detailMap = list.get(i);
				Special_Claim bean = new Special_Claim();
				BeanUtils.populate(bean, detailMap);
				claimList.add(bean);
			}
		}

		if (claimList.size() != 0) {
			for (Special_Claim special_Claim : claimList) {
				Special_ClaimExample example = new Special_ClaimExample();
				Special_ClaimExample.Criteria criteria = example.createCriteria();
				criteria.andStateNotEqualTo(ConstantSqm.STATUS_DELETE);
				criteria.andSupplierIdEqualTo(Integer.parseInt(StringUtil.fixup(special_Claim.getId())));
				criteria.andYearEqualTo(special_Claim.getYear());
				List<Special_Claim> dataList = special_ClaimDAO.selectSpecial_ClaimByExample(example);
				if (dataList != null && dataList.size() != 0) {
					for (Special_Claim special_Claim2 : dataList) {
						special_Claim2.setState(ConstantSqm.STATUS_DELETE);
						special_ClaimDAO.updateSpecial_ClaimByPrimaryKey(special_Claim2);
					}
				}

			}
		}

	}

	/**
	 * zhouwei 系统导入保存
	 * 
	 * @param entity
	 * @return
	 */
	@Override
	public void txInsertForSys(List<SpecialClaimImportDto> specialClaimImportDtoList) {
		if (null == specialClaimImportDtoList) {
			throw new SystemException("提交数据不能为空");
		}
		for (SpecialClaimImportDto s : specialClaimImportDtoList) {
			if (s.getiFirstJanuary() != null || s.getiSecondJanuary() != null || s.getiThirdJanuary() != null || s.getiFourthJanuary() != null) {
				txAddOrUpdateForSys(1, s, s.getiFirstJanuary(), s.getiSecondJanuary(),s.getiThirdJanuary(), s.getiFourthJanuary());
			}
			if (s.getiFirstFebruary() != null || s.getiSecondFebruary() != null || s.getiThirdFebruary() != null || s.getiFourthFebruary() != null) {
				txAddOrUpdateForSys(2, s, s.getiFirstFebruary(), s.getiSecondFebruary(),s.getiThirdFebruary(), s.getiFourthFebruary());
			}
			if (s.getiFirstMarch() != null || s.getiSecondMarch() != null || s.getiThirdMarch() != null || s.getiFourthMarch() != null) {
				txAddOrUpdateForSys(3, s, s.getiFirstMarch(), s.getiSecondMarch(),s.getiThirdMarch(), s.getiFourthMarch());
			}
			if (s.getiFirstApril() != null || s.getiSecondApril() != null || s.getiThirdApril() != null || s.getiFourthApril() != null) {
				txAddOrUpdateForSys(4, s, s.getiFirstApril(), s.getiSecondApril(),s.getiThirdApril(), s.getiFourthApril());
			}
			if (s.getiFirstMay() != null || s.getiSecondMay() != null || s.getiThirdMay() != null || s.getiFourthMay() != null) {
				txAddOrUpdateForSys(5, s, s.getiFirstMay(), s.getiSecondMay(),s.getiThirdMay(), s.getiFourthMay());
			}
			if (s.getiFirstJune() != null || s.getiSecondJune() != null || s.getiThirdJune() != null || s.getiFourthJune() != null) {
				txAddOrUpdateForSys(6, s, s.getiFirstJune(), s.getiSecondJune(),s.getiThirdJune(), s.getiFourthJune());
			}
			if (s.getiFirstJuly() != null || s.getiSecondJuly() != null || s.getiThirdJuly() != null || s.getiFourthJuly() != null) {
				txAddOrUpdateForSys(7, s, s.getiFirstJuly(), s.getiSecondJuly(),s.getiThirdJuly(), s.getiFourthJuly());
			}
			if (s.getiFirstAugust() != null || s.getiSecondAugust() != null || s.getiThirdAugust() != null || s.getiFourthAugust() != null) {
				txAddOrUpdateForSys(8, s, s.getiFirstAugust(), s.getiSecondAugust(),s.getiThirdAugust(), s.getiFourthAugust());
			}
			if (s.getiFirstSeptember() != null || s.getiSecondSeptember() != null || s.getiThirdSeptember() != null || s.getiFourthSeptember() != null) {
				txAddOrUpdateForSys(9, s, s.getiFirstSeptember(), s.getiSecondSeptember(),s.getiThirdSeptember(), s.getiFourthSeptember());
			}
			if (s.getiFirstOctober() != null || s.getiSecondOctober() != null || s.getiThirdOctober() != null || s.getiFourthOctober() != null) {
				txAddOrUpdateForSys(10, s, s.getiFirstOctober(), s.getiSecondOctober(),s.getiThirdOctober(), s.getiFourthOctober());
			}
			if (s.getiFirstNovember() != null || s.getiSecondNovember() != null || s.getiThirdNovember() != null || s.getiFourthNovember() != null) {
				txAddOrUpdateForSys(11, s, s.getiFirstNovember(), s.getiSecondNovember(),s.getiThirdNovember(), s.getiFourthNovember());
			}
			if (s.getiFirstDecember() != null || s.getiSecondDecember() != null || s.getiThirdDecember() != null || s.getiFourthDecember() != null) {
				txAddOrUpdateForSys(12, s, s.getiFirstDecember(), s.getiSecondDecember(),s.getiThirdDecember(), s.getiFourthDecember());
			}
		}
	}
	
	public List<Special_Claim> findListByStateDelete(Special_Claim entity) {
		Special_ClaimExample example = new Special_ClaimExample();
		Special_ClaimExample.Criteria criteria = example.createCriteria();
		criteria.andStateEqualTo(ConstantSqm.STATUS_DELETE);
		criteria.andSupplierIdEqualTo(entity.getSupplierId());
		criteria.andYearEqualTo(entity.getYear());
		return special_ClaimDAO.selectSpecial_ClaimByExample(example);
	}
	public List<Special_Claim> findListByStateMonth(Special_Claim entity) {
		Special_ClaimExample example = new Special_ClaimExample();
		Special_ClaimExample.Criteria criteria = example.createCriteria();
		criteria.andStateEqualTo(ConstantSqm.STATUS_NORMAL);
		criteria.andSupplierIdEqualTo(entity.getSupplierId());
		criteria.andYearEqualTo(entity.getYear());
		criteria.andMonthEqualTo(entity.getMonth());
		return special_ClaimDAO.selectSpecial_ClaimByExample(example);
	}
	/**
	 * 新增或者修改，系統导入
	 * @param month
	 * @param incomingImportDto
	 */
	public void txAddOrUpdateForSys(int month,SpecialClaimImportDto specialClaimImportDto,String first,String second,String third,String fourth){
		Special_Claim bean = null;
		Special_ClaimExample example = new Special_ClaimExample();
		Special_ClaimExample.Criteria criteria = example.createCriteria();
		List<Supplier> supplierList=supplierService.findSupplierByCode(specialClaimImportDto.getSupplierCode());
		if(supplierList!=null&&supplierList.size()>0){
			specialClaimImportDto.setSupplierId(Integer.parseInt(StringUtil.fixup(supplierList.get(0).getId())));
			specialClaimImportDto.setSupplierName(supplierList.get(0).getName());
		}
		criteria.andStateNotEqualTo(ConstantSqm.STATUS_DELETE);
		criteria.andSupplierIdEqualTo(Integer.parseInt(StringUtil.fixup(specialClaimImportDto.getSupplierId())));
		criteria.andYearEqualTo(specialClaimImportDto.getYear());
		criteria.andMonthEqualTo(String.valueOf(month));
		List<Special_Claim> specialClaimList = special_ClaimDAO.selectSpecial_ClaimByExample(example);
		// 修改
		if (specialClaimList.size() != 0) {
			bean = specialClaimList.get(0);
			if(first!=null&&StringUtil.isNotEmpty(first)){
				bean.setIncident1(Integer.parseInt(first));
			}
			if(second!=null&&StringUtil.isNotEmpty(second)){
				bean.setIncident2(Integer.parseInt(second));
			}
			if(third!=null&&StringUtil.isNotEmpty(third)){
				bean.setIncident3(Integer.parseInt(third));
			}
			if(fourth!=null&&StringUtil.isNotEmpty(fourth)){
				bean.setIncident4(Integer.parseInt(fourth));
			}
			special_ClaimDAO.updateSpecial_ClaimByPrimaryKey(bean);
		}else{
			Special_Claim specialClaim = new Special_Claim();
			org.springframework.beans.BeanUtils.copyProperties(specialClaimImportDto, specialClaim);
			if(first!=null&&StringUtil.isNotEmpty(first)){
				specialClaim.setIncident1(Integer.parseInt(first));
			}
			if(second!=null&&StringUtil.isNotEmpty(second)){
				specialClaim.setIncident2(Integer.parseInt(second));
			}
			if(third!=null&&StringUtil.isNotEmpty(third)){
				specialClaim.setIncident3(Integer.parseInt(third));
			}
			if(fourth!=null&&StringUtil.isNotEmpty(fourth)){
				specialClaim.setIncident4(Integer.parseInt(fourth));
			}
			specialClaim.setState(ConstantSqm.STATUS_NORMAL);
			specialClaim.setMonth(StringUtil.fixup(month));
			special_ClaimDAO.insertSpecial_Claim(specialClaim);
		}
	}
}
